﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YAPL.Language.Core.Exceptions;
using YAPL.Language.Core.Types;

namespace YAPL.Language.Core.Lib.Strings
{
	public class Reverse : YAPLFunction
	{

		public Reverse() : base(FunctionNames.Reverse, GCL.Get(ClassNames.YAPLString)) {}

		public override YAPLObject Call(Scope scope) {
			ParseScope(scope);
			var str = scope[SELF_PARAMETER] as YAPLString;
			if (str != null) {
				var chars = str.StrValue.ToCharArray();
				Array.Reverse(chars);
				return new YAPLString(new string(chars));
			}
			throw new YAPLException("bad calling object");
		}
	}
}
